Skip to content

Documentation about float - #1

Open
massimosala wants to merge 4310 commits into
massimosala:masterfrom
micropython:master
Open

massimosala wants to merge 4310 commits into
massimosala:masterfrom
micropython:master

Conversation

@massimosala

Copy link
Copy Markdown
Owner

Hi

Please see
micropython#11735

The official page
https://docs.micropython.org/en/latest/genrst/builtin_types.html#float
should be updated about the different result of

float('_')

(and eventually other inconsistencies) between Python and MicroPython.

robert-hh and others added 29 commits July 17, 2026 22:47
The events are put in the ringbuf when a callback is scheduled.It can
then be obtained using can.irq().flags() and provides the IRQ_FLAGS
state at the moment when the callback was scheduled.

Signed-off-by: robert-hh <robert@hammelrath.com>
- No TX queue index reported for sent messages.
- Unable to cancel a specific message.
- No exact numbers reported for the number of messages in the
  TX/RX queue

Signed-off-by: robert-hh <robert@hammelrath.com>
It was 0, but that was to high affecting other operations. Now it is
at 80, in the range of other medium speed I/O devices.

Change suggested by Damian George.

Signed-off-by: robert-hh <robert@hammelrath.com>
To calculate RTSS_Hx_CLK frequency.

Signed-off-by: Damien George <damien@micropython.org>
This commit implements watchdog timer support on the alif port.  On the HP
core with default clock settings it supports a timeout of up to 10.7s.

When the watchdog fires it triggers the NMI IRQ handler, so custom code is
added to reset the SoC when that occurs.

Signed-off-by: Damien George <damien@micropython.org>
Signed-off-by: Damien George <damien@micropython.org>
Waiting for the link has a 5 second timeout, and the system should sleep
efficiently and poll/process other events while waiting.

Fixes issue #19410.

Signed-off-by: Damien George <damien@micropython.org>
Required by the include-based linker script support that follows.

Signed-off-by: Phil Howard <github@gadgetoid.com>
Pico SDK 2.3.0 makes its default linker script overridable via includes,
so the port no longer needs to carry a full copy. Replace the monolithic
memmap_mp_rp2040.ld and memmap_mp_rp2350.ld with memmap_mp_rp2.ld, which
includes the SDK default, plus small override fragments under memmap_rp2/,
memmap_rp2040/ and memmap_rp2350/ that supply only the MicroPython parts:
the FLASH/FLASH_FS split, moving gc/vm/parse into RAM, and the GC heap and
stack layout.

Memory region boundaries are unchanged.

Co-authored-by: Phil Howard <github@gadgetoid.com>
Signed-off-by: Phil Howard <github@gadgetoid.com>
ROMFS is carved off the top of the code space (just below the user
filesystem) by rp2_flash.c, but the FLASH region only excluded the
filesystem, so the application region overlapped ROMFS. A firmware that
grew into ROMFS was not caught by the linker, only by a debug-only
runtime assert.

Add MICROPY_HW_ROMFS_BYTES as a CMake variable, feeding both a linker
defsym and a compile definition from one source, and give ROMFS its own
FLASH_ROMFS region so the FLASH application region excludes it. The
linker now fails at build time if the firmware overlaps ROMFS. With the
default of 0 bytes the layout is unchanged.

Signed-off-by: Phil Howard <github@gadgetoid.com>
Bring the port's runtime_init_clocks() in line with the pico-sdk
2.3.0 version, since it was originally derived from this function.

PLL_COMMON_REFDIV is deprecated in the SDK in favour of the separate
PLL_SYS_REFDIV and PLL_USB_REFDIV macros; use those so a board that
only sets the new per-PLL values is honoured, and so the port keeps
building if the deprecated macro is eventually removed.

Configure the divide-by-1 clocks (ref, sys, usb, adc, peri, hstx)
with clock_configure_undivided(), and clk_rtc with
clock_configure_int_divider(), as the SDK now does. Both avoid the
64-bit division that clock_configure() pulls in to compute a
fractional divider.

Drop the --wrap=runtime_init_clocks linker flag: the SDK declares
runtime_init_clocks() as __weak, so a plain strong definition in the
port overrides it, which makes the wrap redundant.

Also switch the HSTX guard to HAS_HSTX and take RTC_CLOCK_FREQ_HZ
from hardware/rtc.h, matching upstream. No functional change to the
clock configuration on existing boards.

Signed-off-by: Phil Howard <github@gadgetoid.com>
Without -fno-math-errno the compiler must keep sqrt()/sqrtf() as library
calls so they can set errno on a domain error, even though the Cortex-M33
FPU has a single VSQRT.F32 instruction. MicroPython's math module
detects domain errors via isnan/isinf checks on the result rather than
errno, so disabling errno here is safe and lets sqrt leverage hardware.

Benchmarked on a Pico 2 (RP2350, perfbench N=150 M=100, avg of 3):
misc_mandel (complex abs() in its inner loop) improves by ~12%, with no
measurable change to non-sqrt benchmarks and a slightly smaller binary.

Signed-off-by: Phil Howard <github@gadgetoid.com>
The combination of 8d6ce0f and
111d2e9 produced a build failure for
RP2350 targets.  But it did not actually fail the build due to a
regression introduced by e6380fa.

Fix the rp2 build issue by including `hardware_powman`.

Signed-off-by: Damien George <damien@micropython.org>
rp2/CMakeLists.txt: Use quoted literals for the BTstack
and oofatfs config files, so the escaped double quotes don't
break syntax highlighting in VSCode and GitHub's web UI.

Signed-off-by: Phil Howard <github@gadgetoid.com>
The bundled TinyUSB device endpoint-transfer API gained a trailing
bool is_isr argument on usbd_edpt_xfer()/usbd_edpt_xfer_fifo() and on
the matching dcd_edpt_xfer()/dcd_edpt_xfer_fifo() driver entry points,
and the stm32_fsdev driver was split into a shared fsdev_common.c.
Adapt the in-tree users so the bump builds across ports:

- extmod/machine_usb_device.c: pass is_isr=false on the
  USBDevice.submit_xfer() path (never an ISR), guarded by
  TUSB_VERSION_NUMBER so ports building against an older bundled
  TinyUSB (e.g. esp32 via ESP-IDF) still compile.
- ports/alif/tinyusb_port: the port's custom dcd driver takes the
  new argument on both entry points (unused by this driver).
- ports/stm32: build the new lib/tinyusb fsdev_common.c, which
  provides the PMA/btable helpers used by dcd_stm32_fsdev.c.

Signed-off-by: Andrew Leech <andrew@alelec.net>
4KB CDC buffers max out USB packet movement performance with HS USB.

Signed-off-by: Kwabena W. Agyeman <kwagyeman@live.com>
Works for bytes.decode() and str constructor.

Previously ascii arg was treated the same as utf8, now only 7-bit
bytes are treated as valid ascii characters.

This work was funded through GitHub Sponsors.

Signed-off-by: Angus Gratton <angus@redyak.com.au>
bytes() constructor uses the same code path.

Also brings over the same supported encodings check for the
bytes constructor that already exists for str.encode().

This work was funded through GitHub Sponsors.

Signed-off-by: Angus Gratton <angus@redyak.com.au>
Partially this is documenting some additional limitations
added recently now that the encoding argument is not totally
ignored.

This work was funded through GitHub Sponsors.

Signed-off-by: Angus Gratton <angus@redyak.com.au>
Latest mDNS is 1.11.3 but it adds quite a lot of code size and static RAM
usage. This version seems to fix our ESP32-H2 build issue without as much
bloat.

This work was funded through GitHub Sponsors.

Signed-off-by: Angus Gratton <angus@redyak.com.au>
This reverts commit 67f7fdd.

Updated mdns component (in parent commit) no longer fails to compile.

Signed-off-by: Angus Gratton <angus@redyak.com.au>
This work was funded through GitHub Sponsors.

Signed-off-by: Angus Gratton <angus@redyak.com.au>
May save a small amount of resources as this chip has no Wi-Fi.

Signed-off-by: Angus Gratton <angus@redyak.com.au>
Signed-off-by: Ihor Nehrutsa <Ihor.Nehrutsa@gmail.com>
Fixes exception when doing "mpremote cp file :"
or "mpremote mip install os-path", when
os.stat() returns stat_result namedtuple instead of plain tuple.

This is the case if one has done "mip install os-path"
Ref micropython/micropython-lib@f4cfc3c

Example exception:

    ValueError: malformed node or string on line 1:
     Call(func=Name(id='stat_result', ctx=Load()), args=[],
     keywords=[keyword(arg='st_mode',
       value=Constant(value=16384, kind=None)), ...
     keyword(arg='st_ctime', value=Constant(value=0, kind=None))])

Issue found by @snowkoli

Signed-off-by: Jon Nordby <jononor@gmail.com>
Without leading ./ then will get error like this:

    < env: ‘test_errno.sh’: No such file or directory

Signed-off-by: Jon Nordby <jononor@gmail.com>
Signed-off-by: jaenrig-ifx <enriquezgarcia.external@infineon.com>
Signed-off-by: jaenrig-ifx <enriquezgarcia.external@infineon.com>
Signed-off-by: jaenrig-ifx <enriquezgarcia.external@infineon.com>
projectgus and others added 30 commits September 16, 2026 10:09
Regression since v1.23 (exact commit unknown).

Adds a unit test that fails without this fix, and succeeds with it.
(Test is added in extmod_hardware but currently doesn't pass on any other
ports that I have access to...)

This work was funded through GitHub Sponsors.

Signed-off-by: Angus Gratton <angus@redyak.com.au>
The ESP32-C5 bootloader lives at 0x2000, as on the other C5 boards, but
this board's deploy instructions said to write the firmware at 0.  Doing
so leaves no valid image at the bootloader offset and the ROM loops on
"invalid header".

Fixes issue #19696.

Signed-off-by: Tejas Nagmote <tejasnagmote520@gmail.com>
D13 and D15 were mapped to each other's GPIO.  Per the Seeed Studio
wiki pin map and the board schematic, D13 is wired to GPIO21 (SCL1)
and D15 to GPIO19.  This also makes D13 agree with the existing
SCL1 entry (GPIO21) and D14 with SDA1 (GPIO20).

Co-Authored-By: Claude <noreply@anthropic.com>
Signed-off-by: cumin <13809292481@163.com>
machine.RTC will now keep its value after machine.reset()
or machine.deepsleep().

Only changes behaviour on RP2350. On RP2040 the AON timer is never running
at this point, but it may be possible to keep it on by changing
mp_machine_reset().

This work was funded through GitHub Sponsors.

Signed-off-by: Angus Gratton <angus@redyak.com.au>
__StackLimit is __bss_end__ + MICROPY_C_HEAP_SIZE, so it inherits the
alignment of __bss_end__. newlib's malloc grows its arena to page
boundaries, and _sbrk refuses anything past __StackLimit, so growth
fails with the heap partly free.

Boards linking C++ user modules malloc during static init, before USB
is up, where PICO_MALLOC_PANIC halts the core with no output. Whether
a build fails depends on where the link put __bss_end__.

Round the ceiling up to a page. MICROPY_C_HEAP_SIZE of 0 still gives a
ceiling of exactly __bss_end__.

Signed-off-by: Phil Howard <github@gadgetoid.com>
This commit lets `machine.lightsleep` restore the original CPU and
peripherals frequencies upon wakeup if they were previously set to
different values than the defaults.

The original implementation of `machine.lightsleep` would restore the
default speed for CPU and peripherals as part of the wakeup procedure,
which would ignore previously set values.  These changes force an
optional frequency values set once the MCU wakes up, by simply jumping
into the internal implementation for `machine.freq`.

The relevant lightsleep test was also updated to verify the changes in
question.

Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
Signed-off-by: AkshayChandra-IFX <akshaychandra.nagzarkar@infineon.com>
Signed-off-by: NaveenChengappa-IFX <Naveen.Chandura@infineon.com>
Signed-off-by: AkshayChandra-IFX <akshaychandra.nagzarkar@infineon.com>
Signed-off-by: NaveenChengappa-IFX <Naveen.Chandura@infineon.com>
The peripheral clock divider type (bit resolution) was selected
only from the requested divider value, always choosing the
minimum required resolution.

That behavior caused two issues in divider allocation.

First, not every peripheral exposes every divider resolution type.
If a low-resolution divider was requested on hardware lacking
that type, allocation failed even when a compatible
higher-resolution divider was available.

Second, even when all divider types existed, allocation was too
strict: once all minimum-resolution dividers were used, free
higher-resolution ones were ignored, even though they were valid
for the same target clock destination and settings.

With this change, allocation now falls back to any compatible
free divider type.

Signed-off-by: jaenrig-ifx <enriquezgarcia.external@infineon.com>
Signed-off-by: jaenrig-ifx <enriquezgarcia.external@infineon.com>
Signed-off-by: jaenrig-ifx <enriquezgarcia.external@infineon.com>
Signed-off-by: jaenrig-ifx <enriquezgarcia.external@infineon.com>
Signed-off-by: jaenrig-ifx <enriquezgarcia.external@infineon.com>
Signed-off-by: jaenrig-ifx <enriquezgarcia.external@infineon.com>
Signed-off-by: IFX-Anusha <Anusha.TR@infineon.com>
Signed-off-by: NaveenChengappa-IFX <Naveen.Chandura@infineon.com>
Signed-off-by: IFX-Anusha <Anusha.TR@infineon.com>
Signed-off-by: NaveenChengappa-IFX <Naveen.Chandura@infineon.com>
Signed-off-by: NaveenChengappa-IFX <Naveen.Chandura@infineon.com>
Use the RTC irq handler to call the handler if required. Defining
the proper IRQ handler for the IRQ table was missing.

Signed-off-by: robert-hh <robert@hammelrath.com>
That makes it available for the code and it is used
by machine.deepsleep().

Signed-off-by: robert-hh <robert@hammelrath.com>
machine.deepsleep(ms) works now as intended by powering down the board
for ms/1000 seconds and then resetting it. That can be repeated several
times.

For MIMXRT10xx MCUs machine.deepsleep() works as intended. The WAKEUP
pin pull-up was enabled and set to 100k to ensure a high/low transition.

machine.deepsleep() does not work as intended for mimxrt1176. It can be
called once and recover from deepsleep by pulling the WAKEUP_DIG pin
low, but then attempts to call machine.deepsleep with or without a
timeout fail until a power cycle is done. So waking up from deepsleep
using the WAKEUP_DIG pin is not enabled. It is however possible to
wakeup the device with >1 sec low pulse at the ONOFF pin.

Signed-off-by: robert-hh <robert@hammelrath.com>
DEEPSLEEP_RESET is already returned by `machine.reset_cause()` and now also
exposed as a constant.  HARD_RESET is not yet used but will be in a
follow-up commit.

Signed-off-by: Damien George <damien@micropython.org>
The `machine.reset_cause()` function was only partially working on mimxrt.
This commit fixes the following:
- SOFT_RESET is now set only after a soft reset at the REPL.
- HARD_RESET is now set correctly on boot (previously it used SOFT_RESET).

Signed-off-by: Damien George <damien@micropython.org>
DEEPSLEEP_RESET is now set as the reset cause when the timer alarm, WAKEUP
or ONOFF pins wake the device.  And the cause is reset after reading it so
the logic works the next time around.

Signed-off-by: Damien George <damien@micropython.org>
Using hard ABI passes floats in floating point registers, which is what
MicroPython's native .mpy format expects.

(All other bare-metal ports use this ABI setting: alif, nrf, psoc-edge,
renesas-ra, samd and stm32.)

Signed-off-by: Damien George <damien@micropython.org>
This makes it explicit which MCU the board targets (now that there is also
the RP2350).  Only RPI_PICO and MACHDYNE_WERKZEUG previously had this set,
now all 25 RP2040-based boards do.

Signed-off-by: Damien George <damien@micropython.org>
Prior to pico-sdk 2.3.0 all RP230 ARM boards were built unconditionally
with `-mfloat-abi=softfp`, which uses hardware instructions for float
operations but passes float arguments in integer registers.  That's
incompatible with MicroPython's native .mpy ABI, which expects float
arguments to be passed in the float registers.

In 2.3.0 pico-sdk added PICO_HARD_FLOAT_ABI which allows the build to
select `-mfloat-abi=hard`, passing floats in float registers.  Enable that
option on all RP2350 ARM boards so they can import and use native .mpy
files containing float code.

Signed-off-by: Damien George <damien@micropython.org>
Signed-off-by: Phil Howard <github@gadgetoid.com>
pico-sdk 2.3.1 narrowed default_text_excludes.incl to libgcc and libm,
which would move libc.a and the newlib mem* objects back to flash.

The rp2 override keeps them in SRAM; this is now a deliberate
divergence. Note that libc.a only matches on RISC-V builds, where
newlib is linked from libc.a rather than libg.a.

Signed-off-by: Phil Howard <github@gadgetoid.com>
This commit lets the ESP32 port makefile work in environments set up via
EIM (Espressif's SDK/toolchain manager) instead of the regular SDK
export script.

EIM-activated environment do not place `idf.py` into the system's PATH,
so the Makefile needs to know where to look for it if it cannot be found
right away.  However, EIM does set up an environment variable that
points to the environment root, and therefore picking up idf.py from
there is trivial.  As a bonus, if the makefile cannot find idf.py, it
will report a more sensible error to the user rather than a generic
"file not found" message.

The documentation was also updated to mention EIM and the current state
of things when using such a tool to manage your ESP-IDF SDKs.

Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
This commit updates the build infrastructure to undo the local compiler
takeover done by Espressif's EIM tool, allowing the ESP32 port to build
correctly from an EIM-activated environment.

EIM would blindly edit the PATH environment variable to replace any
local LLVM installation with its own bare-metal version, and add all
directories named `bin` from their tools directory.  Three of those
directories have files whose name clashes with local GCC installations.

As we may build `mpy-cross` for the host system as part of the build
process of the ESP32 port, that's unfortunately a workaround we have to
add ourselves.

Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.